﻿<%@ Page Language="c#" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>

<script runat="server">

    
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (Page.IsPostBack)
        {            
            String username = txtName.Text;
            String password = txtPwd.Text;

            object connStr = ConfigurationSettings.AppSettings["sqlConn"];
            using (SqlConnection conn = new SqlConnection(connStr.ToString()))
            {
                using (SqlCommand command = conn.CreateCommand())
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "sp_login_select";
                    command.Parameters.Add("id", SqlDbType.Int).Value = 0;
                    command.Parameters.Add("name", SqlDbType.VarChar, 30).Value = username;
                    command.Parameters.Add("log_status", SqlDbType.VarChar, 6).Value = "irl";

                    conn.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.FieldCount != 1)
                    {
                        if (reader.Read())
                        {
                            if (password.Equals((String)reader[2]))
                            {
                                Response.Cookies["irl_id"].Value = reader[0].ToString();
                                Response.Cookies["irl_name"].Value = reader[1].ToString();
                                Response.Cookies["irl_log_status"].Value = "irl";
                                Response.Cookies["irl_security"].Value = reader[4].ToString();
                                Response.Cookies["irl_client_id"].Value = reader[3].ToString();
                                if (reader[6] != DBNull.Value)
                                {
                                    Response.Cookies["office"].Value = reader[6].ToString();
                                }
                                if (reader[7] != DBNull.Value)
                                {
                                    Response.Cookies["irl_role"].Value = reader[7].ToString();

                                }
                                Response.Redirect("default2.aspx");
                            }
                            else
                            {
                                // Response.Redirect("default2.aspx");
                                lblError.Text = "Your password was not correct, please try again!";                                
                            }
                            
                        }

                    }
                    else
                    {
                        lblError.Text = "Invalid Username and Password, please try again!";
                    }
                }
            }
        }
        
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Description" content="Providing the tools and expertise needed to navigate in the emerging consumer markets of Indochina." />
<meta name="keywords" content="Research in Indochina, Research Consultants in Indochina, Marketing Research in Indochina, Marketing Research Companies in Indochina, Marketing Consultants in Indochina Research in Vietnam, Research Consultants in Vietnam, Marketing Research in Vietnam, Marketing Research Companies in Vietnam, Marketing Consultants in Vietnam Research in Cambodia, Research Consultants in Cambodia, Marketing Research in Cambodia, Marketing Research Companies in Cambodia, Marketing Consultants in Cambodia Research in Laos, Research Consultants in Laos, Marketing Research in Laos, Marketing Research Companies in Laos, Marketing Consultants in Laos" />
<meta name="robots" content="all">

<title>Indochina Research</title>
<link rel="SHORTCUT ICON" href="~/irl.ico" type="image/x-icon" />
<link type="text/css" rel="stylesheet" href="css/style_1.css" />

<script language="javascript" type="text/javascript">
function LogIn(){
	var f;
	var log_name;
	var pwd;
	var str;
	
	f = document.forms['LoginForm'];
	log_name = f.txtName.value;
	pwd = f.txtPwd.value;
	str = ""
	
	if (log_name == "" && pwd == ""){
		alert("Please enter your user name and password to log in.");
		f.txtName.focus();
	}
	else if (log_name == ""){
		alert("Information does not complete.\nPlease enter your user name.");		
		f.txtName.focus();
	}
	else if (pwd == ""){
		alert("Information does not complete.\nPlease enter your password.");
		f.txtPwd.focus();
	}
	else{
		f.submit();
		return true;
	}
}
</script>
</head>

<body>
<table width="773" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td width="765" height="540" align="center" valign="top" style="border:solid 1px #10147e;" >
			<!-- header -->			
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr bgcolor="#F4F4F9">
					<td colspan="3" align="right" style="padding:10px;">
						<b class="blueL">Client Management System</b>
					</td>
				</tr>
				<tr>
					<td class="wave_l">&nbsp;
						</td>
					<td><img src="images/wave_logo.jpg" width="107" height="83"></td>
					<td class="wave_r">&nbsp;
						</td>
				</tr>
				<tr>
					<td colspan="3" style="padding:0 20px;">&nbsp;
						
					</td>
				</tr>
				
			</table>
			
			
			
			<!-- body -->
			<table border="0" width="100%" height="60%" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center" style="padding:20px;">					
						<h3 class="blueL">Please login.</h3>
						<br />
						<br />
						<!-- Login -->
			            <form id="LoginForm" runat="server">
			            <div>			
			                <table border="0" align="center" cellpadding="3" cellspacing="0">
			                    <tr>
			                        <td><div class="login"><asp:TextBox ID="txtName" MaxLength="30" runat="server" /></div></td>
			                        <td><div class="login"><asp:TextBox ID="txtPwd" TextMode="Password" MaxLength="20" runat="server"
			                            onKeyPress="if(event.keyCode==13){LogIn();}" /></div></td>
			                    </tr>
			                    <tr align="center">
			                        <td><b class="blueL">Login Name</b></td>
			                        <td><b class="blueL">Password</b></td>
			                    </tr>
			                </table>
			                <div>
			                
			                    <br />
                                <asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>
			                
			                </div>
			                
			            </div>
			            </form>
					</td>
				</tr>
			</table>
			
			
			
		</td>
		
		<td width="6" class="rightShadow" valign="top">
			<img src="images/white.gif" width="6" height="6" /></td>
	</tr>
	
	<!-- bottom shadow -->
	<tr>
		<td height="6" class="bottomShadow">
			<img src="images/white.gif" width="6" height="6" /></td>
		
		<td width="6" height="6">
			<img src="images/shadow_corner.gif" width="6" height="6" /></td>
	</tr>
</table>
</body>
</html>
